package com.aiflow.system;

import com.aiflow.bean.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 自定义session拦截器，30s后失效
 * 
 * @author polly
 *
 */
@SuppressWarnings("serial")
public class SessionIterceptor extends AbstractInterceptor{

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
    	System.out.println("session失效了！！！");
        ActionContext ctx = invocation.getInvocationContext();
        Action action = (Action) invocation.getAction();  
        User user = (User) ctx.getSession().get("user");
        if (action instanceof loginAction) {  
            return invocation.invoke();  
        } 
        if(user!=null){
            return invocation.invoke();
        }
        //如果超时，返回提示页面
        return "login";
    }
}